//
//  ReceiveRangeView.swift
//  MyTest
//
//  Created by guanzhongwang on 2021/5/10.
//

import UIKit

class ReceiveRangeView: UIView {
    var delegate:ReceiveRangeViewDelegate?
    private let titleLabel = UILabel()
    private let icon = UIButton(type: .custom)
    var id = 0;
    init() {
        super.init(frame: CGRect.zero)
        backgroundColor = .white
        addSubview(titleLabel)
        titleLabel.font = Font_Size_14
        titleLabel.textColor = B000_COLOR
        titleLabel.snp.makeConstraints({
            $0.centerY.equalToSuperview()
            $0.left.equalTo(15)
        })
        
        addSubview(icon)
        icon.snp.makeConstraints({
            $0.centerY.equalToSuperview()
            $0.right.equalToSuperview().inset(15)
        })
        let image = UIImage(named: "allright")?.withRenderingMode(.alwaysTemplate)
        icon.setImage(image, for: .selected)
        icon.tintColor = .orange
        addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(tap)))
    }
    @objc func tap(){
        self.delegate?.viewSelected(id: self.id)
    }
    func setTitle(_ title:String,id:Int) {
        titleLabel.text = title
        self.id = id
    }
    
    func changeState(selected:Bool) {
        icon.isSelected = selected
    }
    override func draw(_ rect: CGRect) {
        super.draw(rect)
        addBottomBorder()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
}
protocol ReceiveRangeViewDelegate {
    func viewSelected(id:Int);
}
